from django.http import FileResponse
from django.shortcuts import render
from django.utils.encoding import escape_uri_path

from .static import files


# Create your views here.

def download_template(request):
    file = open(r'D:\\python web练习\\Django框架\\django_practice\\视图层实例\\download_file\\myapp\\static\\files\\测试.txt', 'rb')
    response = FileResponse(file)
    response['Content-Type'] = 'application/octet-stream'
    # response['Content-Disposition'] = 'attachment;filename="测试.txt"'
    response['Content-Disposition'] = "attachment;filename*=UTF-8''{}".format(escape_uri_path('测试.txt'))
    return response


def index(request):
    return render(request, 'myapp/index.html')